// 云函数入口文件
const cloud = require("wx-server-sdk")
cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
  try {
    console.log('云函数的event', event, 'openId', cloud.getWXContext().OPENID);
    const result = await cloud.openapi.subscribeMessage.send({
      // touser: event.openid,
      touser: cloud.getWXContext().OPENID, // 获取openId
      page: 'pages/index/index',
      lang: 'zh_CN',
      data: {
        thing2: {
          value: event.theme
        },
        thing6: {
          value: event.roomName
        },
        thing1: {
          value: event.nickName
        },
        date3: {
          value: event.startTime
        },
        thing8: {
          value: event.desc
        }
      },
      templateId: event.MESSAGE_TMPID,
      miniprogramState: 'developer'
    })
    console.log(result)
    return result
  } catch (err) {
    console.log(err);
    return err
  }
}

